import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:star_author/widgets/empty_view/h_empty_view.dart';
import 'package:pull_to_refresh_notification/pull_to_refresh_notification.dart';

class PullToRefreshHeader extends StatelessWidget {
  const PullToRefreshHeader(this.info);

  final PullToRefreshScrollNotificationInfo? info;

  static double headerMaxDragOffset = 80;

  @override
  Widget build(BuildContext context) {
    final double offset = info?.dragOffset ?? 0.0;

    String text = '';
    Widget icon = Container();
    if (info?.mode == RefreshIndicatorMode.armed) {
      icon = Icon(Icons.refresh, color: Colors.grey);
      text = '松手刷新';
    } else if (info?.mode == RefreshIndicatorMode.refresh ||
        info?.mode == RefreshIndicatorMode.snap) {
      icon = CupertinoActivityIndicator();
      text = '加载中...';
    } else if (info?.mode == RefreshIndicatorMode.done) {
      text = '刷新成功';
    } else if (info?.mode == RefreshIndicatorMode.drag ||
        info?.mode == RefreshIndicatorMode.canceled) {
      icon = Icon(Icons.arrow_downward, color: Colors.grey);
      text = '下拉刷新';
    }
    return Container(
      height: offset,
      alignment: Alignment.center,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          icon,
          HEmptyView(10.w),
          Text(
            text,
            style: TextStyle(
              fontSize: 14.sp,
              color: Colors.grey,
            ),
          ),
        ],
      ),
    );
  }
}
